package com.tushen.datacenter.ts;

import android.util.Log;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UdpReceiveThread extends Thread {

    private final String TAG = "UdpReceiveThread";

    //
    public UdpReceiveThread(){
    }

    @Override
    public void run() {
        Log.d(TAG, "receiving... ");
        try {
            DatagramSocket socket = new DatagramSocket(53212); //
            byte data[] = new byte[1024*8];
            DatagramPacket packet = new DatagramPacket(data, data.length);
            while (true){
                socket.receive(packet); // 阻塞式，接收发送方的packet
                String result = new String(packet.getData(), packet.getOffset(), packet.getLength());
                Log.d(TAG, "received ");
                Log.d(TAG, "receive massage: " + result);


            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.d(TAG, "run: " + e.getMessage());
        }

    }

}
